#include <cstdio>
//#include <rp>
const int Limit_Size = 2000 + 10;

bool map[ Limit_Size ][ Limit_Size ];
int max_right[ Limit_Size ][ Limit_Size ], max_down[ Limit_Size ][ Limit_Size ];
int n, max_matrix, count;

void init( )
{
    int i, j;
    char tmp[ Limit_Size ];
    scanf("%d", &n);
    for ( i = 0; i < n; i++ )
    {
        scanf("%s", tmp);
        for ( j = 0; j < n; j++ )
            map[ i ][ j ] = tmp[ j ] - '0';
    }
    for ( i = 0; i < n; i++ )
        max_right[ i ][ n - 1 ] = max_down[ n - 1 ][ i ] = 0;
    for ( i = 0; i < n; i++ )
        for ( j = n - 2; j >= 0 ; j-- )
        {
            if ( map[ i ][ j ] ^ map[ i ][ j + 1 ] )
                max_right[ i ][ j ] = max_right[ i ][ j + 1 ] + 1;
            else
                max_right[ i ][ j ] = 0;
            if ( map[ j ][ i ] ^ map[ j + 1 ][ i ] )
                max_down[ j ][ i ] = max_down[ j + 1 ][ i ] + 1;
            else
                max_down[ j ][ i ] = 0;
        }
/*    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < n; j++ )
            printf("%d ", max_down[ i ][ j ]);
        printf("\n");
    }*/
    max_matrix = 1;
    count = 0;
}

void work( )
{
    int i, j, k, minc, t;
    for ( i = 0; i < n; i++ )
    {
        for ( j = 0; j < n; j++ )
        {
            if ( map[ j ][ i ] && max_down[ j ][ i ] >= max_matrix - 1 && max_right[ j ][ i ] >= max_matrix - 1 )
            {
            //    printf("%d %d ", j, i);
                minc = j;
            //    printf("%d ", max_right[ minc ][ i ]);    
                t = 1;
                for ( k = j + 1; k <= j + max_down[ j ][ i ] && k - j + i < n; k++ )
                {
                    if ( max_right[ minc ][ i ] > max_right[ k ][ i ] )
                        minc = k;
            //        printf("%d ", minc);
                    if ( max_right[ minc ][ i ] < k - j )
                        break;
                    t++;
                }
            //    printf("%d\n", t);
                if ( max_matrix == t )
                    count++;
                if ( max_matrix < t )
                {
                    count = 1;
                    max_matrix = t;
                }
                if ( max_matrix > t )
                    j = minc;
            }
        }
    }
}

void print( )
{
    printf("%d %d\n", max_matrix, count);
}

int main( )
{
    int t;
    while ( scanf("%d", &t) != EOF )
        while ( t-- )
        {
            init( );
            work( );
            print( );
        }
    return 0;
}
